home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / TCL1 / __MANDEL / MANDELBR / CPIXMAP.C < prev    next >
Text File  |  1992-05-31  |  3KB  |  172 lines

  1. /******************************************************************************
  2.  CPixMap.c
  3.  
  4.                             The PixMap Class
  5.         
  6.     SUPERCLASS = CBitMap
  7.  
  8.  ******************************************************************************/
  9.  
  10. #include "Global.h"
  11. #include "CPixMap.h"
  12. #include "TCLUtilities.h"
  13. #include "CDesktop.h"
  14.  
  15. #include "LongQD.h"
  16.  
  17. extern CDesktop        *gDesktop;
  18.  
  19. PicHandle    gPixPictH;
  20.  
  21. void    CPixMap::IPixMap(Rect    aBoundsRect, short aDepth)
  22. {
  23.     GrafPtr        aSavedPortP;
  24.     GDHandle    aSavedDeviceH;
  25.     GWorldPtr    aGWorldP;
  26.     
  27.     GetGWorld(&aSavedPortP, &aSavedDeviceH);
  28.     FailOSErr(NewGWorld(&aGWorldP, aDepth, &aBoundsRect, NULL, NULL, 0));
  29.     SetGWorld(aSavedPortP, aSavedDeviceH);
  30.     
  31.     itsGWorldP = aGWorldP;
  32.     itsBoundsRect = aBoundsRect;
  33.     itsXferMode = srcCopy;
  34. }
  35.  
  36. void    CPixMap::Dispose()
  37. {
  38.     ForgetPtr(itsCQDProcs);
  39.     if (itsGWorldP)
  40.         DisposeGWorld(itsGWorldP);
  41.  
  42.     inherited::Dispose();                /* Pass message on to superclass    */
  43. }
  44.  
  45. void    CPixMap::SetXferMode(short theMode)
  46. {
  47.     itsXferMode = theMode;
  48. }
  49.  
  50. short    CPixMap::GetXferMode(void)
  51. {
  52.     return itsXferMode;
  53. }
  54.  
  55. void    CPixMap::GetBounds(
  56.     Rect        *theBounds)
  57. {
  58.     *theBounds = itsBoundsRect;
  59.                         /* Return copy of instance variable    */
  60. }
  61.  
  62. short    CPixMap::GetWidth(void)
  63. {
  64.     return itsBoundsRect.right - itsBoundsRect.left;
  65. }
  66.  
  67. short    CPixMap::GetHeight(void)
  68. {
  69.     return itsBoundsRect.bottom - itsBoundsRect.top;
  70. }
  71.  
  72. void    CPixMap::CopyFrom(
  73.     LongRect        *fromRect,
  74.     LongRect        *toRect,
  75.     RgnHandle    maskRgn)
  76. {
  77.     PixMapHandle    aPixMapH = GetPixMapHandle();
  78.     
  79.     if (LockPixels(aPixMapH))
  80.     {
  81.         LCopyBits((BitMap *)*aPixMapH,
  82.             &thePort->portBits,
  83.              fromRect, toRect, itsXferMode, maskRgn);
  84.         
  85.         UnlockPixels(aPixMapH);
  86.     }
  87. }
  88.  
  89. void    CPixMap::BeginDrawing()
  90. {
  91.     GrafPtr        aSavedPortP;
  92.     GDHandle    aSavedDeviceH;
  93.     
  94.     if (! LockPixels(GetPixMapHandle()))
  95.         Failure(QDError(), 0);
  96.  
  97.     GetGWorld(&aSavedPortP, &aSavedDeviceH);
  98.     SetGWorld(itsGWorldP, NULL);
  99.     
  100.     itsSavedPortP = aSavedPortP;
  101.     itsSavedDeviceH = aSavedDeviceH;
  102. }
  103.  
  104. void    CPixMap::EndDrawing()
  105. {
  106.     SetGWorld(itsSavedPortP, itsSavedDeviceH);
  107.     UnlockPixels(GetPixMapHandle());
  108. }
  109.  
  110. PixMapHandle CPixMap::GetPixMapHandle(void)
  111. {
  112.     return GetGWorldPixMap(itsGWorldP);
  113. }
  114.  
  115. Ptr CPixMap::GetBaseAddr(void)
  116. {
  117.     return GetPixBaseAddr(GetPixMapHandle());
  118. }
  119.  
  120. short CPixMap::GetRowBytes(void)
  121. {
  122.     return (**GetPixMapHandle()).rowBytes & 0x1FFF;
  123. }
  124.  
  125. short CPixMap::GetPixelSize(void)
  126. {
  127.     return (**GetPixMapHandle()).pixelSize;
  128. }
  129.  
  130. PicHandle CPixMap::GetPicHandle(void)
  131. {
  132.     PicHandle        aPictH;
  133.     PixMapHandle    aPixMapH;
  134.     Rect            aBoundsRect;
  135.     
  136.     BeginDrawing();
  137.     
  138.     aBoundsRect = itsBoundsRect;
  139.     aPixMapH = GetPixMapHandle();
  140.     gPixPictH = NULL;
  141.     gPixPictH = OpenPicture(&aBoundsRect);
  142.     
  143.     CopyBits(*aPixMapH, *aPixMapH, &aBoundsRect, &aBoundsRect, srcCopy, NULL);
  144.     
  145.     ClosePicture();
  146.     EndDrawing();
  147.     
  148.     return gPixPictH;
  149. }
  150.  
  151. void CPixMap::SetPutPicProc(ProcPtr thePutPicProc)
  152. {
  153.     BeginDrawing();
  154.     UseStdProcs();
  155.     itsGWorldP->grafProcs = itsCQDProcs;
  156.     itsCQDProcs->putPicProc = thePutPicProc;
  157.     EndDrawing();
  158. }
  159.  
  160. void CPixMap::UseStdProcs(void)
  161. {
  162.     itsCQDProcs = (CQDProcs *)NewPtr(sizeof(CQDProcs));
  163.     FailNIL(itsCQDProcs);
  164.     
  165.     SetStdCProcs(itsCQDProcs);
  166. }
  167.  
  168. void CPixMap::ResetStdProcs(void)
  169. {
  170.     ForgetPtr(itsCQDProcs);
  171.     itsGWorldP->grafProcs = NULL;
  172. }